/** 
    @file pixelmail.hpp
    @brief Mailbox for messaging between game objects
*/

#ifndef PM3_PIXELMAIL_HPP
#define PM3_PIXELMAIL_HPP

#include <string>
#include <OgreSingleton.h>

#define PM_NO_MAIL  "DUMMY"

namespace pm3 {

    /**
        @class PIXELPOST
        @brief A simple message with no arguments
    */
    class PIXELPOST {
    public:
            /**
                @brief Constructor
                @param[in] s_type Post type
            */
            PIXELPOST( const std::string &s_type = PM_NO_MAIL );
            /**
                @brief Destructor
            */
            virtual ~PIXELPOST();

            /**
                @brief Assignment operator
            */
            virtual PIXELPOST& operator=( const PIXELPOST &r_post );

            /**
                @brief Returns the type of the message
                @return Message type
            */
            inline std::string get_type() const {
                return m_type;
            }

    private:
            //! Message type
            std::string m_type;
    };

    /**
        @class PIXELMAIL
        @brief Message queue
    */
    class PIXELMAIL: public Ogre::Singleton<PIXELMAIL> {
    public:
            /**
                @brief Constructor
            */
            PIXELMAIL();
            /**
                @brief Destructor
            */
            ~PIXELMAIL();

            /**
                @brief Posts a message into the queue
                @param[in] r_post Reference to the message to post
            */
            void post( const PIXELPOST &r_post );

            /**
                @brief Takes the oldest message from the queue
                @return The message
            */
            PIXELPOST take();

            /**
                @brief Cleans the whole message queue
            */
            void clean();

    private:
            //! A list of messages
            std::list<PIXELPOST> m_posts;
    };

    //! Mail global
    extern PIXELMAIL g_mail;
}

#endif

